package com.ruoyi.business.appuser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.system.domain.vo.BusOrderVo;
import com.ruoyi.system.service.IBusOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 订单Controller
 *
 * @author Tellsea
 * @date 2024-04-11
 */
@Api(tags = "订单Controller")
@RestController
@RequestMapping("/business/order")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class BusOrderController extends BaseController {

    private final IBusOrderService busOrderService;

    @ApiOperation("查询订单列表")
    @PreAuthorize("@ss.hasPermi('business:order:list')")
    @GetMapping("/list")
    public TableDataInfo<BusOrderVo> list(BusOrderVo entity) {
        entity.setState("1");
        return busOrderService.queryList(entity);
    }

    @ApiOperation("查询订单所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(BusOrderVo entity) {
        return AjaxResult.success("查询成功", busOrderService.queryAll(entity));
    }

    @ApiOperation("导出订单列表")
    @PreAuthorize("@ss.hasPermi('business:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusOrderVo entity) {
        List<BusOrderVo> list = busOrderService.queryAll(entity);
        ExcelUtil<BusOrderVo> util = new ExcelUtil<>(BusOrderVo.class);
        util.exportExcel(response, list, "订单数据");
    }

    @ApiOperation("获取订单详细信息")
    @PreAuthorize("@ss.hasPermi('business:order:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("查询成功", busOrderService.getById(id));
    }

    @ApiOperation("新增订单")
    @PreAuthorize("@ss.hasPermi('business:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody BusOrderVo entity) {
        return toAjax(busOrderService.save(entity));
    }

    @ApiOperation("修改订单")
    @PreAuthorize("@ss.hasPermi('business:order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody BusOrderVo entity) {
        return toAjax(busOrderService.updateById(entity));
    }

    @ApiOperation("删除订单")
    @PreAuthorize("@ss.hasPermi('business:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(busOrderService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
